import { Injectable } from "@angular/core";
import { Resolve } from "@angular/router";
import { forkJoin, Observable } from "rxjs";
import { first } from "rxjs/internal/operators";
import { Banner, SongSheet } from "src/app/services/conmmon.type";
import { HomeService, SheetParams } from "src/app/services/home.service";

type DataType = [Banner[], SongSheet[], SongSheet[], SongSheet[]]

@Injectable()
export class MusicResolver implements Resolve<DataType> {
    listParams: SheetParams = {
        cat: '民谣',
        order: 'hot',
        offset: 1,
        limit: '20',
    };
    constructor(private service: HomeService) { }

    resolve(): Observable<DataType> {
        let a = this.service.getBanners()
        let b = this.service.getPerosonalSheetList()
        this.listParams.cat = "民谣";
        let c = this.service.getSheets(this.listParams)
        this.listParams.cat = "欧美";
        let d = this.service.getSheets(this.listParams)

        return forkJoin([a, b, c, d]).pipe(first())
    }
}